<?php
/**
 * 产品模型
 *
 * @copyright   Copyright 2011, Richie
 * @author      Richie <richbossman@163.com>
 * @package     SMS
 * @link        http://www.letphp.com
 * 
 * $Id: StoreModel.class.php 72 2011-04-07 01:18:00Z 442767452@qq.com $
 */

class StoreModel extends SMSModel {
	//数据验证
	protected $_validate	=	array(
		array('name','checkName', '仓库名称已经存在！',0,'callback'),
	);
	//自动完成
	protected $_auto = array(
		array('add_time', 'time', 1, 'function'),
		array('update_time', 'time', 3, 'function')
	);
	
	//检查名称是否存在
	function checkName(){
		$map['name'] = $_POST['name'];
        if(!empty($_POST['id'])) {
			$map['id']	=	array('neq',$_POST['id']);
        }
		$result	=	$this->where($map)->field('id')->find();
        if($result) {
        	return false;
        }else{
			return true;
		}
	}
	
	//返回数组的仓库
	function storeOptions(){
		return $this->order('sort ASC, id DESC')->getField('id,name');
	}
}
?>